home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d11 / ev678dev.arc / X15BOX.ASM < prev    next >
Assembly Source File  |  1990-07-03  |  8KB  |  281 lines

  1. ;------------------------------------------------------------------------
  2. ;Example program which sets Everex Extended Mode 15h, 512x480 256 color
  3. ;and draws a box around the perimeter of the screen.  This code uses
  4. ;Everex Extended BIOS function 0004h to get the paging function pointer
  5. ;for the particular card installed.  This code works on the Everex EVGA
  6. ;(Ev673), Everex Viewpoint VGA (Ev678), and the Everex Ultragraphics II
  7. ;VGA (Ev236), as well as all future Everex VGA cards, since it uses the
  8. ;device independent paging function pointer to perform memory paging.
  9. ;------------------------------------------------------------------------
  10. ;The paging function is used to change which 64K bank of memory is mapped
  11. ;into the CPU address space at segment A000.  The banks start at 0 at the
  12. ;top of the screen, and increment towards the bottom of the screen.  Each
  13. ;bank is 64K in size and is read/writeable.  This paging function code can
  14. ;be applied to high-resolution 16-color modes as well.
  15. ;------------------------------------------------------------------------
  16.  
  17. CR    equ    0Dh
  18. LF    equ    0Ah
  19.  
  20. rSequAddr    equ    3C4h
  21. rRMiscOutp    equ    3CCh
  22. rWMiscOutp    equ    3C2h
  23.  
  24. ;------------------------------------------------------------------------
  25.  
  26.     cseg    segment word public 'CODE'
  27.  
  28.     assume    cs:cseg
  29.     assume    ds:cseg
  30.     assume    es:cseg
  31.  
  32. ;------------------------------------------------------------------------
  33.  
  34.     org    0100h
  35.  
  36. Start:
  37.     mov    bx,0000h    ;Everex Extended BIOS Get Status
  38.     mov    ax,7000h
  39.     int    10h        ;Find out if Everex card is present
  40.                 ;and what kind it is.
  41.  
  42.     cmp    al,70h        ;Abort if not Everex VGA card
  43.     je    EverexCardDetected
  44.     jmp    EverexCardNotPresent
  45.  
  46. EverexCardDetected:
  47.     mov    ax,0070h
  48.     mov    bl,15h        ;Set Everex Extended 512x480 256-color
  49.     int    10h        ;mode.  Assume that setmode succeeds.
  50.  
  51.     and    dx,0FFF0h    ;Check card type from Get Status call
  52.     cmp    dx,6730h    ;Is it an EVGA?
  53.     je    SkipGetPaging
  54.  
  55.                 ;Note that paging function is called
  56.                 ;AFTER the setmode above.
  57.     mov    bx,0004h    ;Everex Extended Get Paging Function
  58.     mov    ax,7000h
  59.     int    10h
  60.  
  61.     cmp    al,70h
  62.     je    CopyPagingFunction
  63.     jmp    CantGetPageFunc    ;Abort if paging function not supported
  64.  
  65. CopyPagingFunction:
  66.     mov    si,es
  67.     mov    ds,si
  68.     mov    si,di        ;DS:SI -> Paging function in ROM
  69.  
  70.     mov    di,cs
  71.     mov    es,di
  72.     mov    di,offset ProgPage    ;Point to our internal function
  73.  
  74.     mov    cx,ds:[si-02h]    ;Get size of function in bytes
  75.  
  76.     rep    movsb        ;Copy function to our memory
  77.  
  78.     mov    al,cs:[ExampleRET]
  79.     mov    es:[di-01h],al    ;Patch RETF to RET
  80.  
  81. SkipGetPaging:            ;Re-entry here for EVGA
  82.                 ;We're now in 512x480 256-color mode
  83.                 ;and ProgPage contains a paging function
  84.                 ;for the current Everex VGA card, so
  85.                 ;let's draw the box.
  86.  
  87.     mov    di,0A000h
  88.     mov    es,di        ;ES = segment of graphics memory
  89.  
  90.  
  91.     mov    dl,00h        ;Note that 512x480 has a neat performance
  92.     call    SetPage        ;advantage in that 512 is a power of 2,
  93.                 ;and thus divides into 65536 (64K) evenly.
  94.                 ;In other words, one 64K bank contains
  95.                 ;exactly 128 scan lines, whereas a 640
  96.                 ;wide mode has a fractional scan line.
  97.  
  98.     mov    di,0000h    ;Point to first scan line
  99.     mov    cx,512d/2    ;Fill 512/2 = 256 words
  100.     mov    ax,0707h    ;Fill with white pixels
  101.     rep    stosw        ;Draw top horizontal line
  102.  
  103.  
  104.     mov    ax,479d        ;This is an easy example of how to calculate
  105.     mov    dx,512d        ;The page and offset of a scanline or pixel
  106.     mul    dx        ;479 is the scan line we want, and each scan
  107.                 ;line is 512 bytes wide.
  108.     add    ax,0000h    ;Add in the starting X pixel.  (This isn't
  109.     adc    dl,00h        ;much here, since X is 0, but it's given as
  110.                 ;and example.)
  111.     call    SetPage        ;Now AX = offset within the bank, and DL
  112.                 ;contains the bank number we need to map
  113.                 ;into our window.
  114.     mov    di,ax        ;Point to last scan line
  115.     mov    cx,512d/2    ;Fill 512/2 = 256 words
  116.     mov    ax,0707h    ;Fill with white pixels
  117.     rep    stosw        ;Draw bottom horizontal line
  118.  
  119.  
  120.     mov    dl,00h
  121.     call    SetPage        ;Map in top bank
  122.  
  123.     mov    di,0000h    ;Point to upper left corner of screen
  124.     mov    bx,512d        ;Offset from one pixel to the one below it.
  125.     mov    cx,480d        ;Number of pixels to do vertically
  126.     mov    al,07h        ;Draw white pixels
  127.  
  128. DrawLeftSideLoop:
  129.     mov    es:[di],al    ;Draw one pixel
  130.     add    di,bx        ;Move down to next
  131.     jnc    DrawLeftSideCont    ;Did we move past the end of a segment
  132.  
  133.     inc    dl        ;Yes, so move to next page
  134.     call    SetPage    
  135.  
  136. DrawLeftSideCont:
  137.     loop    DrawLeftSideLoop    ;and loop
  138.  
  139.  
  140.     mov    dl,00h
  141.     call    SetPage        ;Map in top bank
  142.  
  143.     mov    di,511d        ;Point to upper right corner of screen
  144.     mov    bx,512d        ;Offset from one pixel to the one below it.
  145.     mov    cx,480d        ;Number of pixels to do vertically
  146.     mov    al,07h        ;Draw white pixels
  147.  
  148. DrawRightSideLoop:
  149.     mov    es:[di],al    ;Draw one pixel
  150.     add    di,bx        ;Move down to next
  151.     jnc    DrawRightSideCont    ;Did we move past the end of a segment
  152.  
  153.     inc    dl        ;Yes, so move to next page
  154.     call    SetPage    
  155.  
  156. DrawRightSideCont:
  157.     loop    DrawRightSideLoop    ;and loop
  158.  
  159.  
  160.     mov    dl,00h        ;Map bank back to top bank
  161.     call    SetPage
  162.  
  163.     mov    dx,cs
  164.     mov    ds,dx
  165.     mov    dx,offset ProgramDoneMesg
  166.     mov    ah,09h
  167.     int    21h
  168.  
  169.     mov    ax,4C00h    ;Return code OK
  170.     int    21h        ;Program done
  171.  
  172. ;------------------------------------------------------------------------
  173.  
  174. EverexCardNotPresent:    ;Abort if not Everex VGA card
  175.     mov    dx,offset NotEverexCardMesg
  176.     jmp    short OutputErrorMesg
  177.  
  178. CantGetPageFunc:    ;Abort if paging function not supported
  179.     mov    dx,offset CantGetPageMesg
  180. OutputErrorMesg:
  181.     mov    ax,cs
  182.     mov    ds,ax
  183.     mov    ah,09h
  184.     int    21h
  185.  
  186.     mov    ax,4C01h    ;Exit with error return code
  187.     int    21h
  188.  
  189. ;------------------------------------------------------------------------
  190.  
  191. ActivePage    db 00h        ;Global variable holding current bank number
  192.  
  193. ProgramDoneMesg    label    byte
  194.     db 'Program successful.',CR,LF,'$'
  195.  
  196. NotEverexCardMesg    label    byte
  197.     db 'ERROR: Everex VGA card not detected.',CR,LF,'$'
  198.  
  199. CantGetPageMesg        label    byte
  200.     db 'ERROR: Can not obtain Everex paging function.',CR,LF,'$'
  201.  
  202. ;------------------------------------------------------------------------
  203. ;Memory paging function for Everex EVGA (Ev673) for Everex Extended
  204. ;256-color modes.  Note that this code only works on the EVGA.  For
  205. ;other Everex VGA cards, this code will be overwritten with the
  206. ;paging function code for the particular Everex VGA card installed.
  207. ;------------------------------------------------------------------------
  208. ;Entry:    DL = page number to select
  209.  
  210. SetPage        proc    near
  211.     
  212.     mov    cs:[ActivePage],dl    ;Keep a copy around for other
  213.                     ;functions to look at, like mouse
  214.                     ;handlers.
  215. ProgPage    proc    near
  216.  
  217.     push    dx
  218.     push    bx
  219.     push    ax
  220.  
  221.     mov    bl,dl
  222.     mov    bh,dl
  223.  
  224.     mov    dx,rSequAddr        ; Set page bit in Sequencer
  225.     mov    al,8            ; This selects between 0,2 and 1,3
  226.     mov    ah,al            ; Save for later reference
  227.     out    dx,al
  228.     inc    dx
  229.     jmp    short $+2
  230.     in    al,dx            ; Get old value
  231.  
  232.     ror    bl,1
  233.     and    bl,80h
  234.     and    al,7fh
  235.     or    al,bl
  236.  
  237.     xchg    ah,al            ; AL = EvrxCtrl1, AH = new bits
  238.     dec    dx
  239.     out    dx,ax
  240.     jmp    short $+2
  241.  
  242.     and    bh,2
  243.     shl    bh,1
  244.     shl    bh,1
  245.     shl    bh,1
  246.     shl    bh,1
  247.     
  248.     xor    bh,20h            ; Invert bit
  249.     mov    dx,rRMiscOutp        ; Now read other register
  250.     in    al,dx
  251.     mov    dx,rWMiscOutp
  252.  
  253.     and    al,0DFh
  254.     or    al,bh
  255.     out    dx,al
  256.  
  257.     pop    ax
  258.     pop    bx
  259.     pop    dx
  260.     ret
  261.  
  262.     db    (100 - ($ - offset ProgPage)) dup (00h)
  263.                     ;Pad buffer out to 256 bytes
  264.                     ;for copying paging code in here.
  265.  
  266. ExampleRet    label    byte    ;Used to patch the RETF in the paging
  267.     ret            ;code to a RET for near calls to
  268.                 ;ProgPage
  269. ProgPage    endp
  270.  
  271. SetPage        endp
  272.  
  273. ;------------------------------------------------------------------------
  274.  
  275. cseg    ends
  276.  
  277.     end    Start
  278.  
  279. ;------------------------------------------------------------------------
  280.  
  281.